<?php

namespace App\Models\Traits;

use Illuminate\Support\Facades\Redis;

trait HasUserStormRunningCache
{
	public function runningRecordsCacheKey(): string
	{
		return "user_{$this->id}_running_gold_records";
	}

	public function addRecordToRunningCache($cacheId)
	{
		Redis::zAdd($this->runningRecordsCacheKey(), 1, $cacheId);
	}

	public function addRecordToRunningExamineCache($cacheId)
	{
		Redis::zAdd($this->runningRecordsCacheKey(), 999, $cacheId);
	}

	public function delRecordFromRunningCache($cacheId)
	{
		Redis::zRem($this->runningRecordsCacheKey(), $cacheId);
	}

	public function isRecordInRunningCache($cacheId): bool
	{
		return Redis::zScore($this->runningRecordsCacheKey(), $cacheId) == 1;
	}
}
